package com.ithema.manger3.service;

import com.ithema.manger3.dao.StudentDao;
import com.ithema.manger3.domain.Student;

public class StudentService {
    //创建StudentDao对象
    StudentDao studentDao=new StudentDao();

    //添加学生不需要什么方法
    public boolean addStudent(Student stu) {
        //调用StudentDao中的addStudent方法
        //StudentDao studentDao=new StudentDao();
        return studentDao.addStudent(stu);
    }
//查看学生
    public Student[] findAllStudent() {
        //调用StudentDao中的findAllStudent方法
        Student[]stu= studentDao.findAllStudent();
        //遍历并判断数组是否为空
        for (int i = 0; i < stu.length; i++) {
            Student stus=stu[i];
            if(stus!=null){
                return stu;
            }
        }return null;
    }
//判断学号是否存在于数组中
    public boolean isExist(String sid) {
        //调用StudentDao方法findAllStudent方法查看所有数组
        Student[]students=studentDao.findAllStudent();
        //遍历数组
        for (int i = 0; i < students.length; i++) {
            Student stu=students[i];
            if(stu!=null&&sid.equals(stu.getSid())){
                return true;
            }
        }return false;
    }

//删除学生,上面已对学号进行判断,所以本次不用再判断,直接调用方法删除
    public void deleteStudent(String sid) {
        //调用StudentDao中的deleteStudent方法删除
        studentDao.deleteStudent(sid);
    }
//修改学生信息
    public void updateStudent(String updateSid, Student updateStu) {
        //调用StudentDao中的updateStudent方法修改
        studentDao.updateStudent(updateSid,updateStu);
    }
}
